//--------------------------------------------------------------------------
// $Id: Constants.java 4 2006-08-20 18:34:48Z zendragon $
//--------------------------------------------------------------------------
// Copyright 2006 Social Brain Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//--------------------------------------------------------------------------

package org.socialbrain.openid;

import org.apache.commons.lang.StringUtils;

import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;

/**
 * @author <a href="http://erning.net/">Zhang Erning</a>
 * @version $Id: Constants.java 4 2006-08-20 18:34:48Z zendragon $
 */
public class Constants
{
    public static final String LINK_REL_OPENID_SERVER   = "openid.server";
    public static final String LINK_REL_OPENID_DELEGATE = "openid.delegate";

    public static final String PARAMETER_PREFIX         = "openid.";
    public static final int    PARAMETER_PREFIX_LENGTH  = PARAMETER_PREFIX.length();

    public static final String PARAM_MODE               = "mode";
    public static final String PARAM_ASSOC_TYPE         = "assoc_type";
    public static final String PARAM_ASSOC_HANDLE       = "assoc_handle";
    public static final String PARAM_CONTACT            = "contact";
    public static final String PARAM_ENC_MAC_KEY        = "enc_mac_key";
    public static final String PARAM_ERROR              = "error";
    public static final String PARAM_ERROR_CODE         = "error_code";
    public static final String PARAM_EXPIRES_IN         = "expires_in";
    public static final String PARAM_DH_CONSUMER_PUBLIC = "dh_consumer_public";
    public static final String PARAM_DH_GEN             = "dh_gen";
    public static final String PARAM_DH_MODULUS         = "dh_modulus";
    public static final String PARAM_DH_SERVER_PUBLIC   = "dh_server_public";
    public static final String PARAM_IDENTITY           = "identity";
    public static final String PARAM_INVALIDATE_HANDLE  = "invalidate_handle";
    public static final String PARAM_IS_VALID           = "is_valid";
    public static final String PARAM_MAC_KEY            = "mac_key";
    public static final String PARAM_NONCE              = "nonce";
    public static final String PARAM_RETURN_TO          = "return_to";
    public static final String PARAM_REFERENCE          = "reference";
    public static final String PARAM_SESSION_TYPE       = "session_type";
    public static final String PARAM_SIGNED             = "signed";
    public static final String PARAM_SIG                = "sig";
    public static final String PARAM_TRUST_ROOT         = "trust_root";
    public static final String PARAM_USER_SETUP_URL     = "user_setup_url";

    public static final String MODE_ASSOCIATE            = "associate";
    public static final String MODE_CANCEL               = "cancel";
    public static final String MODE_CHECK_AUTHENTICATION = "check_authentication";
    public static final String MODE_CHECKID_IMMEDIATE    = "checkid_immediate";
    public static final String MODE_CHECKID_SETUP        = "checkid_setup";
    public static final String MODE_ERROR                = "error";
    public static final String MODE_ID_RES               = "id_res";

    public static final String ERROR_CODE_UNSUPPORTED_TYPE = "unsupported-type";

    public static final String ASSOC_TYPE_HMAC_SHA1   = "HMAC-SHA1";
    public static final String ASSOC_TYPE_HMAC_SHA256 = "HMAC-SHA256";
    public static final String DEFAULT_ASSOC_TYPE     = ASSOC_TYPE_HMAC_SHA1;

    public static final String SESSION_TYPE_BLANK     = StringUtils.EMPTY; // specs 1.1
    public static final String SESSION_NO_ENCRYPTION  = "no-encryption";
    public static final String SESSION_TYPE_DH_SHA1   = "DH-SHA1";
    public static final String SESSION_TYPE_DH_SHA256 = "DH-SHA256";
    public static final String DEFAULT_SESSION_TYPE   = SESSION_TYPE_BLANK;

    public static final BigInteger DEFAULT_DH_MODULUS = new BigInteger(
            "1551728981814736974712322577637155" +
            "3991572480196691540447970779531405" +
            "7629378541917580651227423698188993" +
            "7278161526466314385615958256881888" +
            "8995127215884267541995034125870655" +
            "6549803580104870537681476726513255" +
            "7470407658574792912915723345106432" +
            "4509471500722962109419434978392598" +
            "4760375594985848253359305585439638443");

    public static final BigInteger DEFAULT_DH_GEN = BigInteger.valueOf(2);

    public static final int MAX_HTML_SIZE = 1024 * 1024; // 1M
    public static final String DEFAULT_CHARSET = "UTF-8";
    public static final String FORM_STRING_ENCODING = "UTF-8";

    public static final Map<String, String>DH_ALGORITHM_MAP;
    static
    {
        DH_ALGORITHM_MAP = new HashMap<String, String>();
        DH_ALGORITHM_MAP.put(SESSION_TYPE_DH_SHA1,   "SHA1");
        DH_ALGORITHM_MAP.put(SESSION_TYPE_DH_SHA256, "SHA256");
    }
}
